package com.gyms.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.gyms.R;

import java.util.ArrayList;

import glide.ImageLoaderUtils;
import myInterface.OnItemClickLitener;

/**
 * ltx on 2016/11/11 09:26
 * 约定场馆图片的适配器
 */
public class GymDetailImgAdapter extends RecyclerView.Adapter<GymDetailImgAdapter.ViewHolder>{
    private LayoutInflater mInflater;
    // 场馆图片
    private ArrayList<String> venuePic;
    private Context mContext;
    public GymDetailImgAdapter(Context context)
    {
        mInflater = LayoutInflater.from(context);
        this.mContext=context;
    }

    private OnItemClickLitener mOnItemClickLitener;//Item的点击监听

    public void setOnItemClickLitener(OnItemClickLitener mOnItemClickLitener)
    {
        this.mOnItemClickLitener = mOnItemClickLitener;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = mInflater.inflate(R.layout.gym_img_item,
                parent, false);
        ViewHolder viewHolder = new ViewHolder(view);
        viewHolder.mIvGym= (ImageView) view.findViewById(R.id.iv_gym_img);


        return viewHolder;
    }

    @Override
    public void onBindViewHolder(final ViewHolder holder, final int position) {
        ImageLoaderUtils.display(mContext,holder.mIvGym,venuePic.get(position));

        //如果设置了回调，则设置点击事件
        if (mOnItemClickLitener != null)
        {
            holder.itemView.setOnClickListener(new View.OnClickListener()
            {
                @Override
                public void onClick(View v)
                {
                    mOnItemClickLitener.onItemClick(holder.itemView, position);
                }
            });

        }
    }

    @Override
    public int getItemCount() {
        return null==venuePic?0:venuePic.size();
    }

    public void setVenuePic(ArrayList<String> venuePic) {
        this.venuePic = venuePic;
    }

    public class ViewHolder extends RecyclerView.ViewHolder
    {
        ImageView mIvGym;
        public ViewHolder(View view)
        {
            super(view);
        }


    }
}
